<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/8/27 0027
 * Time: 18:20
 */
namespace app\index\controller;
use app\admin\model\UserModel;
use think\Db;
use think\Request;

class Login
{
    /**登录接口
     * @param Request $request
     * @return string|\think\response\Redirect
     */
    public function index(Request $request){
        $data =  $request->param();
        $val = val($data,[
            'user|账号'=>'require',
            'pwd|密码'=>'require',
            'captcha|验证码'=>'require|captcha',
        ]);
        if(!$val['code']){
            return returns(403,$val['msg']);
        }
        $user = $request->param('user',null);
        $pwd = $request->param('pwd',null);
        $user = UserModel::getIndexUser()->where('user.user',$user)->find();
        if(!$user){
            return returns(401,'账号没有注册');
        }
        if(getPwd($pwd) == $user['pwd']){
            session('user',$user);
            return returns(200,'登录成功');
        }else{
            return returns(403,'密码或账号错误');
        }
    }
}